<template>
  <el-dialog
    :title="formTitle"
    :visible.sync="addDialogVisible"
    width="50%"
    :close-on-click-modal="false"
    @close="addDialogClosed"
  >
    <el-form
      :model="addForm"
      :rules="addFormRules"
      ref="addFormRef"
      label-width="120px"
    >
      <el-form-item label="模板名称" prop="name">
        <el-input v-model="addForm.name"></el-input>
      </el-form-item>
    </el-form>
    <!-- 底部区 -->
    <span slot="footer" class="dialog-footer">
      <el-button @click="addDialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { cloneTemplate } from '@/api/monitor/template/list'

export default {
  data() {
    return {
      formTitle: '克隆模板',
      addDialogVisible: false,
      addForm: {
        name:''
      },
      addFormRules: {},
    }
  },
  methods: {
    open(row) {
      this.addForm = Object.assign({}, row)
      this.addDialogVisible = true
    },
    save() {
      this.$refs.addFormRef.validate(async (valid) => {
        console.log(this.addForm)
        if (!valid) return
        if (this.addForm.templateId) {
        const res =  await cloneTemplate(this.addForm)
        if(res.code == 0){
            this.$message({
            type: 'success',
            message: '克隆成功',
            
          })

        }else{
            this.$message({
            type: 'info',
            message: '克隆失败',
          })
        }
        }
        this.addDialogVisible = false
        this.init()
      })
    },
    addDialogClosed() {
      this.$refs.addFormRef.resetFields()
      this.addDialogVisible = false
      this.$emit('init')
    },
  },
}
</script>

<style>
</style>















